/*
 * @Author: your name
 * @Date: 2021-05-12 16:42:44
 * @LastEditTime: 2021-05-13 14:11:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /vite-project/mock/utils/index.js
 */

const querystring = require('querystring');

function getPostData(req, res) {
    return new Promise((resolve, reject) => {
        let post = '';
        req.on('data', function(chunk) {
            post += chunk;
        });
        req.on('error', function(chunk) {
            reject();
        });
        req.on('end', function() {
            post = querystring.parse(post);
            resolve(post);
        });
    });
}

function resultSuccess(data, token ,message="请求成功！") {
    return {
        code: 0,
        message,
        token,
        result: data
    }
}

function resultError(data="", token=null, message="请求失败！") {
    return {
        code: -1,
        message,
        token,
        result: data,
    };
}

module.exports = {
    getPostData,
    resultSuccess,
    resultError,
};
